var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name :'',
    login:true,
    id:wx.getStorageSync('id'),
    img_url:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535517206419&di=134a7285d082a14b1489dee7f25fcee0&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F0117e2571b8b246ac72538120dd8a4.jpg%401280w_1l_2o_100sh.jpg',
  },
  setTouchMove:function(e){
    var that = this
    app.setTouchMove(e,that)
  },
  //用户登陆
  bindGetUserInfo: function () {
    var that = this
    wx: wx.login({
      success: function (res) {
        var code = res.code
            //用户登陆
            wx: wx.request({
              url: 'https://wx.gjzy.com/weixin/Admin/Index/Onlogin',
              data: {
                "code": code,
              },
              header: {},
              method: 'GET',
              dataType: 'json',
              responseType: 'text',
              success: function (res) {
                console.log(res)
                wx: wx.setStorage({
                  key: 'id',
                  data: res.data,
                  success:function(){
                    wx.redirectTo({
                      url: '../home/home',
                    })
                  }
                })
              },
              fail: function (res) { },
              complete: function (res) { },
            })
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var id = wx.getStorageSync('id')
    if(id == ''){
      that.setData({
        login:true
      })
    }else{
      wx.checkSession({
        success: function (res) {
          wx: wx.getUserInfo({
            success: function (res) {
              that.setData({
                name: res.userInfo.nickName,
                img_url: res.userInfo.avatarUrl,
                login: false
              })
            },
          })
        },
      })
    }
  },
  url2:function(){
    wx.redirectTo({
      url: '../home/home',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})